<?php

/*
 * Create by Indonesian Brain Solutions
 * E-mail : cs@mesinit.com
 * Programmer : sony@sonywibisono.com
 */

class Companies {
    var $id;
    var $company_name;
    var $address;
    var $city;
    var $state;
    var $email;


    function open($id){
        global $db;
        $sql="select * from companies where id=$id";
        $row=$db->fetch_row($sql);
        if (!empty($row)){
            extract($row);
            $this->company_name=$company_name;
            $this->address=$address;
            $this->city=$city;
            $this->state=$state;
            $this->email=$email;

        }
    }

    function openAll(){
        $sql="select * from companies order by id asc";
        $result=$db->query($sql);
        return $db->fetch_array($result);
        
    }

    function insert(){
    global $db;
    $sql="insert into companies values (null,'{$this->company_name}',
'{$this->address}','{$this->city}','{$this->state}','{$this->email}')";
    $db->query($sql);
    return mysql_insert_id();
    }

    function update(){
        global $db;
        $sql="update companies set company_name='{$this->company_name}',
address='{$this->address}',city='{$this->city}',state='{$this->state}',
email='{$this->email}' where id=".$this->id;
        $db->query($sql);
    }

    function delete(){
        global $db;
        $sql="delete from companies where id=".$this->id;
        $db->query($sql);
    }

}
?>
